package com.ti.demo.configuration;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.client.advisor.vectorstore.VectorStoreChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: com.ti.demo.configuration
 * @Author Triagen
 * @Date 2025/7/18 11:12
 */
@Configuration
public class ChatClientConfiguration {
    @Autowired
    private ChatMemory chatMemory;

    @Autowired
    private VectorStore vectorStore;

    /**
     * a manual ChatClient example,for better understanding of api, model and chatClient
     * generally speaking, api includes the connection info, model includes the model choice, and chatClient is the assembly of both
     *
     * @param deepSeekChatModel
     * @return
     */
    @Bean("shortMemoryChatClient")
    public ChatClient shortMemoryChatClient(DeepSeekChatModel deepSeekChatModel) {
        return ChatClient.builder(deepSeekChatModel)
                .defaultAdvisors(
                        SimpleLoggerAdvisor.builder().build(),
                        MessageChatMemoryAdvisor.builder(chatMemory).build())
                .build();
    }


    @Bean("longMemoryChatClient")
    public ChatClient longMemoryChatClient(DeepSeekChatModel deepSeekChatModel) {
        return ChatClient.builder(deepSeekChatModel)
                .defaultAdvisors(
                        SimpleLoggerAdvisor.builder().build(),
                        VectorStoreChatMemoryAdvisor.builder(vectorStore).defaultTopK(10).build())
                .build();
    }


}
